package stool.strategy;

import java.math.BigDecimal;

/**
 * @author Felix YF Dong
 * @date 2021/5/2
 */
public class CashContext {

    private CashSuper cashSuper;

    public CashContext(CashTypeEnum type) throws Exception {
        switch (type) {
            case NORMAL:
                cashSuper = new CashNormal();
                break;
            case REBATE:
                cashSuper = new CashRebate(BigDecimal.valueOf(0.8));
                break;
            case RETURN:
                cashSuper = new CashReturn(BigDecimal.valueOf(500), BigDecimal.valueOf(100));
                break;
            default:
                throw new Exception("This algorithm is not supported at present.");
        }
    }

    public Object getResult(BigDecimal money) {

        return this.cashSuper.acceptCash(money);
    }

}
